const crypto = require("crypto");
/**
 *
 * @param {String} str 要加密的字符串
 * @returns sha256加密后的字符串
 */
const sha256 = (str) => {
    const hash = crypto.createHash("sha256")
    .update(str)
    .digest("hex");
    return Buffer.from(hash, "utf-8").toString();
};
/**
 * 
 * @param {String} str 要加密的字符串 
 * @param {String} salt 给字符串加盐
 * @returns sha256加密且加盐后的字符串
 */
const sha256Plus = (str,salt) => {
    const saltPassword = password + ":" + salt;
    const hash = crypto.createHash("sha256")
    .update(saltPassword)
    .digest("hex");
    return Buffer.from(hash, "utf-8").toString();
};
 
/**
 *
 * @param {String} str 要加密的字符串
 * @returns md5加密后的字符串
 */
const md5 = (str) => {
    const hash = crypto.createHash("md5")
    .update(str)
    .digest("hex");
    return Buffer.from(hash, "utf-8").toString();
};
/**
 * 
 * @param {String} str 要加密的字符串 
 * @param {String} salt 给字符串加盐
 * @returns md5加密且加盐后的字符串
 */
const md5Plus = (str, salt) => {
    const saltPassword = password + ":" + salt;
    const hash = crypto.createHash("md5")
    .update(saltPassword)
    .digest("hex");
    return Buffer.from(hash, "utf-8").toString();
};
module.exports = sha256;
